package com.master.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.master.entity.School;
import com.master.entity.Team;
import com.master.entity.User;

public class ClassDao {
	public List<Team> getAllTeam(){
		List<Team> list = new ArrayList<Team>();
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/adminsys", "root", "123456");
			String sql = "select * from sys_team";
			pstmt = conn.prepareStatement(sql);
			rs = pstmt.executeQuery();
			while(rs.next()){
				Team t = new Team();
				t.setTID(rs.getInt("TID"));
				t.setTEAM_NAME(rs.getString("TEAM_NAME"));
				t.setIS_COMPLETE(rs.getString("IS_COMPLETE"));
				list.add(t);
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return list;
		
	}
	public boolean UpdateTeam(Team t){
		boolean flag = false;
		Connection conn = null;
		PreparedStatement pstmt = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/adminsys", "root", "123456");
			String sql = "update sys_team set TEAM_NAME=?, IS_COMPLETE=? where TID=?";
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, t.getTEAM_NAME());
			pstmt.setString(2, t.getIS_COMPLETE());
			pstmt.setInt(3, t.getTID());

			flag= pstmt.execute(); 
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return flag;
	}
	
}
